﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using OmegaBot;

namespace drone_cc
{
    public partial class dronePaladinSetup : ClassSetupPanel
    {
        dronePaladinCombat combatClass = null;

        public dronePaladinSetup()
        {
            InitializeComponent();
        }

        public dronePaladinSetup(dronePaladinCombat combatClass ) : base()
        {
            // Save a reference to the combat class so you can get to config!
            this.combatClass = combatClass;
            InitializeComponent();

            // Load from config:
            cbx_UseHandofReckoning.Checked = combatClass.Ini.GetBoolean("paladin", "usehandofreckoning", false);
            cbx_CrusaderStrike.Checked = combatClass.Ini.GetBoolean("paladin", "usecrusaderstrike", false);
            cbx_DivineStorm.Checked = combatClass.Ini.GetBoolean("paladin", "usedivinestorm", false);
            cbx_Consecration.Checked = combatClass.Ini.GetBoolean("paladin", "useconsecration", false);
            cbx_ConsecrateOnAdds.Checked = combatClass.Ini.GetBoolean("paladin", "consecrationonadds", false);
            cbx_HammerOfWrath.Checked = combatClass.Ini.GetBoolean("paladin", "usehammerofwrath", false);
            cbx_SmartArtOfWar.Checked = combatClass.Ini.GetBoolean("paladin", "enablesmartartofwar", false);
            cbx_SmartJudge.Checked = combatClass.Ini.GetBoolean("paladin", "enablesmartjudgments", false);
            cbx_Exorsism.Checked = combatClass.Ini.GetBoolean("paladin", "useexorcism", false);
            cbx_FlashOfLight.Checked = combatClass.Ini.GetBoolean("paladin", "useflashoflight", false);
            trk_FlashOFLight.Value = System.Convert.ToInt32(combatClass.Ini.GetString("paladin", "flashpercent"));
            tbx_FlashOfLight.Text = combatClass.Ini.GetString("paladin", "flashpercent");
            cbx_JudgeJustice.Checked = combatClass.Ini.GetBoolean("paladin", "usejudgmentofjustice", false);
            cbx_JudgeWisdom.Checked = combatClass.Ini.GetBoolean("paladin", "usejudgmentofwisdom", false);
            trk_JudgeWisdom.Value = System.Convert.ToInt32(combatClass.Ini.GetString("paladin", "wisdompercent"));
            tbx_JudgeWisdom.Text = combatClass.Ini.GetString("paladin", "wisdompercent");
            cbx_AvengingWrath.Checked = combatClass.Ini.GetBoolean("paladin", "useavengingwrath", false);
            cbx_DivinePlea.Checked = combatClass.Ini.GetBoolean("paladin", "usedivineplea", false);
            cbx_LightHeal.Checked = combatClass.Ini.GetBoolean("paladin", "uselightheal", false);
            trk_LightHeal.Value = System.Convert.ToInt32(combatClass.Ini.GetString("paladin", "lighthealpercent"));
            cbx_BigHeal.Checked = combatClass.Ini.GetBoolean("paladin", "usebigheal", false);
            trk_BigHeal.Value = System.Convert.ToInt32(combatClass.Ini.GetString("paladin", "bighealpercent"));
            
            cbx_UseMount.Checked = combatClass.Ini.GetBoolean("paladin", "usemount", false);
            cbx_SkipLootCheck.Checked = combatClass.Ini.GetBoolean("paladin", "skiplootcheck", false);
            tbx_MountDistance.Text = combatClass.Ini.GetString("paladin", "mountdistance");
            cbx_UseCrusaderAura.Checked = combatClass.Ini.GetBoolean("paladin", "mountusecrusaderaura", false);

            cbx_CombineElementals.Checked = combatClass.Ini.GetBoolean("paladin", "combineitems", false);
            cbx_OpenClams.Checked = combatClass.Ini.GetBoolean("paladin", "openclams", false);

            cbx_EnablePVP.Checked = combatClass.Ini.GetBoolean("paladin", "enablepvp", false);

            //load blessing choice
            switch (combatClass.Ini.GetString("paladin", "useblessing"))
            {
                case "might":
                    rbtn_Might.Checked = true;
                    break;
                case "kings":
                    rbtn_Kings.Checked = true;
                    break;
                case "wisdom":
                    rbtn_Wisdom.Checked = true;
                    break;
                default:
                    rbtn_Might.Checked = true;
                    break;
            }

            //load aura choice
            switch (combatClass.Ini.GetString("paladin", "useaura"))
            {
                case "devotion":
                    rbtn_Devotion.Checked = true;
                    break;
                case "retribution":
                    rbtn_Retribution.Checked = true;
                    break;
                default:
                    rbtn_Retribution.Checked = true;
                    break;
            }

            //load seal choice
            switch (combatClass.Ini.GetString("paladin", "useseal"))
            {
                case "righteousness":
                    rbtn_Righteousness.Checked = true;
                    break;
                case "command":
                    rbtn_Command.Checked = true;
                    break;
                case "vengeance":
                    rbtn_VengeanceCorruption.Checked = true;
                    break;
                default:
                    rbtn_Command.Checked = true;
                    break;
            }
        }

        // Throw a FormInvalidException if there's a problem!
        public override void ValidateClassSetup()
        {
            int TestIntParsed;
            if (!Int32.TryParse(tbx_JudgeWisdom.Text, out TestIntParsed))
                throw new FormInvalidException("Please input a valid percentage to judge wisdom.", tbx_JudgeWisdom);
            // Parsed ok but is it correct value?
            if (TestIntParsed < 1 || TestIntParsed > 100)
                throw new FormInvalidException("Please input a valid percentage to judge wisdom.", tbx_JudgeWisdom);
            
            if (!Int32.TryParse(tbx_FlashOfLight.Text, out TestIntParsed))
                throw new FormInvalidException("Please input a valid percentage to cast flash of light.", tbx_FlashOfLight);
            // Parsed ok but is it correct value?
            if (TestIntParsed < 1 || TestIntParsed > 100)
                throw new FormInvalidException("Please input a valid percentage to cast flash of light.", tbx_FlashOfLight);

            if (!Int32.TryParse(tbx_MountDistance.Text, out TestIntParsed))
                throw new FormInvalidException("Please input a valid safe mounting distance.", tbx_MountDistance);
            // Parsed ok but is it correct value?
            if (TestIntParsed < 1)
                throw new FormInvalidException("Please input a valid safe mounting distance.", tbx_MountDistance);
            // Ok all things are good.
        }

        public override void CommitValues()
        {
            // ValidateClassSetup already got called and didn't crash, so everything must be ok!
            combatClass.Ini.Set("paladin", "usehandofreckoning", cbx_UseHandofReckoning.Checked);
            combatClass.Ini.Set("paladin", "usecrusaderstrike", cbx_CrusaderStrike.Checked);
            combatClass.Ini.Set("paladin", "usedivinestorm", cbx_DivineStorm.Checked);
            combatClass.Ini.Set("paladin", "useconsecration", cbx_Consecration.Checked);
            combatClass.Ini.Set("paladin", "consecrationonadds", cbx_ConsecrateOnAdds.Checked);
            combatClass.Ini.Set("paladin", "usehammerofwrath", cbx_HammerOfWrath.Checked);
            combatClass.Ini.Set("paladin", "enablesmartartofwar", cbx_SmartArtOfWar.Checked);
            combatClass.Ini.Set("paladin", "enablesmartjudgments", cbx_SmartJudge.Checked);
            combatClass.Ini.Set("paladin", "useexorcism", cbx_Exorsism.Checked);
            combatClass.Ini.Set("paladin", "useflashoflight", cbx_FlashOfLight.Checked);
            combatClass.Ini.Set("paladin", "flashpercent", tbx_FlashOfLight.Text);
            combatClass.Ini.Set("paladin", "usejudgmentofjustice", cbx_JudgeJustice.Checked);
            combatClass.Ini.Set("paladin", "usejudgmentofwisdom", cbx_JudgeWisdom.Checked);
            combatClass.Ini.Set("paladin", "wisdompercent", tbx_JudgeWisdom.Text);
            combatClass.Ini.Set("paladin", "useavengingwrath", cbx_AvengingWrath.Checked);
            combatClass.Ini.Set("paladin", "usedivineplea", cbx_DivinePlea.Checked);
            combatClass.Ini.Set("paladin", "uselightheal", cbx_LightHeal.Checked);
            combatClass.Ini.Set("paladin", "lighthealpercent", tbx_LightHeal.Text);
            combatClass.Ini.Set("paladin", "usebigheal", cbx_BigHeal.Checked);
            combatClass.Ini.Set("paladin", "bighealpercent", tbx_BigHeal.Text);
            
            combatClass.Ini.Set("paladin", "usemount", cbx_UseMount.Checked);
            combatClass.Ini.Set("paladin", "skiplootcheck", cbx_SkipLootCheck.Checked);
            combatClass.Ini.Set("paladin", "mountdistance", tbx_MountDistance.Text);
            combatClass.Ini.Set("paladin", "mountusecrusaderaura", cbx_UseCrusaderAura.Checked);
            
            combatClass.Ini.Set("paladin", "combineitems", cbx_CombineElementals.Checked);
            combatClass.Ini.Set("paladin", "openclams", cbx_OpenClams.Checked);

            combatClass.Ini.Set("paladin", "enablepvp", cbx_EnablePVP.Checked);

            //save blessing choice
            if(rbtn_Might.Checked == true){
                combatClass.Ini.Set("paladin", "useblessing", "might");
            }
            else if (rbtn_Kings.Checked == true)
            {
                combatClass.Ini.Set("paladin", "useblessing", "kings");
            }
            else if (rbtn_Wisdom.Checked == true)
            {
                combatClass.Ini.Set("paladin", "useblessing", "wisdom");
            }

            //save aura choice
            if (rbtn_Devotion.Checked == true)
            {
                combatClass.Ini.Set("paladin", "useaura", "devotion");
            }
            else if (rbtn_Retribution.Checked == true)
            {
                combatClass.Ini.Set("paladin", "useaura", "retribution");
            }

            //save aura choice
            if (rbtn_Righteousness.Checked == true)
            {
                combatClass.Ini.Set("paladin", "useseal", "righteousness");
            }
            else if (rbtn_Command.Checked == true)
            {
                combatClass.Ini.Set("paladin", "useseal", "command");
            }
            else if (rbtn_VengeanceCorruption.Checked == true)
            {
                combatClass.Ini.Set("paladin", "useseal", "vengeance");
            }

            combatClass.Ini.Save();
        }

        private void cbx_SmartJudge_CheckedChanged(object sender, EventArgs e)
        {
            if (cbx_SmartJudge.Checked)
            {
                gbx_SmartJudgments.Enabled = true;
            }
            else
            {
                gbx_SmartJudgments.Enabled = false;
            }
        }

        private void cbx_SmartArtOfWar_CheckedChanged(object sender, EventArgs e)
        {
            if (cbx_SmartArtOfWar.Checked)
            {
                gbx_SmartArtOfWar.Enabled = true;
            }
            else
            {
                gbx_SmartArtOfWar.Enabled = false;
            }
        }

        private void trk_FlashOFLight_Scroll(object sender, EventArgs e)
        {
            tbx_FlashOfLight.Text = System.Convert.ToString(trk_FlashOFLight.Value);
        }

        private void trk_JudgeWisdom_Scroll(object sender, EventArgs e)
        {
            tbx_JudgeWisdom.Text = System.Convert.ToString(trk_JudgeWisdom.Value);
        }

        private void cbx_Consecration_CheckedChanged(object sender, EventArgs e)
        {
            if (cbx_Consecration.Checked)
            {
                cbx_ConsecrateOnAdds.Enabled = true;
            }
            else
            {
                cbx_ConsecrateOnAdds.Enabled = false;
            }

        }

        private void trk_LightHeal_Scroll(object sender, EventArgs e)
        {
            tbx_LightHeal.Text = System.Convert.ToString(trk_LightHeal.Value);
        }

        private void trk_BigHeal_Scroll(object sender, EventArgs e)
        {
            tbx_BigHeal.Text = System.Convert.ToString(trk_BigHeal.Value);
        }

        private void cbx_UseMount_CheckedChanged(object sender, EventArgs e)
        {
            if (cbx_UseMount.Checked)
            {
                cbx_UseCrusaderAura.Enabled = true;
                tbx_MountDistance.Enabled = true;
            }
            else
            {
                cbx_UseCrusaderAura.Enabled = false;
                tbx_MountDistance.Enabled = true;
            }
        }


    }
}
